import { Player } from "../../definition/player";
import { PokerSet } from "../poker/set";
import { IAnalyzer, IRecorder } from "../pokergame/factory";

export interface IPlayer {
  // 由game回调的方法
  PlayCardSuccess(cardIndexs: Array<number>): void;     // 出牌成功
  PlayCardError(error: string): void;                   // 出牌错误
  GetReadyStatus(): boolean;                            //
  GetAutoStatus(): boolean;                             //
  GetPlayerUser(): Player;                              //
  GetIndex(): number;                                   //
  SetIndex(index: number): void;                        //
  SetPokerCards(cards: PokerSet): void;                 //
  StartCallScore(): void;                               //
  StartPlay(): void;                                    //
  IsOutOfCards(): boolean;                              // 是否出完牌
  SendMsg(msg: any): void;                              //

  // 响应客户端请求的方法
  JoinGame(gameType: number, gameId: number): void;     // 加入游戏
  CreateGame(gameID: number, baseScore: number): void;  // 创建游戏
  LeaveGame(): void;                                    // 离开游戏
  SayToOthers(msg: any): void;                          // 给同一游戏的其他玩家发消息
  SayToAnother(id: number, msg: any): void;             // 给同意游戏的特定索引玩家发消息
  ResolveMsg(msg: any): void;                           // 处理客户端消息
  Ready(): void;                                        // 玩家准备
  UnReady(): void;                                      // 玩家取消准备
  CallScore(score: number): void;                       // 抢地主
  PlayCards(cards: Array<number>): void;                // 出牌
  Pass(): void;                                         // 过牌
  HintCards(): void;                                    // 提示出牌
  GetPlayedCardIndexs(): Array<number>;                 //
  GetPlayerCards(indexs: Array<number>): PokerSet;      //

  SetPokerRecorder(recorder: IRecorder): void;          //
  SetPokerAnalyzer(analyzer: IAnalyzer): void;          //
}
































export namespace CARD {

  export const enum COLOR {
    spade = 1,    // 黑桃 ♠
    heart = 2,    // 红桃 ♥
    club = 3,     // 梅花 ♣
    diamond = 4,  // 方块 ♦
  }

  export const enum SCORE {
    three = 3,
    four = 4,
    five = 5,
    six = 6,
    seven = 7,
    eight = 8,
    nine = 9,
    ten = 10,
    jack = 11,
    queen = 12,
    king = 13,
    ace = 14,
    two = 16, // 前后隔2，方便顺子判断
    joker_black = 18,
    joker_red = 19,
  }

  // 牌型
  export const enum TYPE {
    none = 0,             // 非法
    wang_zha = 1,         // 王炸 Joker Bomb
    zha = 2,              // 炸弹 Bomb
    one = 3,              // 单张 Single
    two = 4,              // 对子 Double
    three = 5,            // 三张 Triple
    three1 = 6,           // 三带一 Triple Plus One
    three2 = 7,           // 三带二 Triple Plus Two
    one_arr = 8,          // 顺子 Straight
    two_arr = 9,          // 连对 Double Straight
    three_arr = 10,       // 三顺(飞机) Triple Straight
    three_arr_wing = 11,  // 飞机带翅膀 Triple Straight Plus Two
    four2 = 12,           // 四带二 Quartet Plus Two
    // 报单 Single alert
    // 报双 Single alert
    // 要不起 Pass
    // 抢地主 Land Claim / Dibs on Land
    // 不抢 Waive
    // Peasants vs Landlord
  }
}

export interface ICard {
  id: number,
  color: CARD.COLOR,
  score: CARD.SCORE
}

// 初始牌组
export interface ICardGroup {
  cardType: CARD.TYPE,
  cards: ICard[],
  score: CARD.SCORE
}

export const dizhuScoreArray: Array<number> = new Array<number>(0, 1, 2, 3);

export enum Timer {
  jiaodizhu = 10 * 1000,  // 叫地主
  qiangdizhu = 10 * 1000, // 抢地主
  play = 20 * 1000        // 出牌
}

export enum GameState {
  xipai = 1,        // 洗牌
  jiaodizhu = 2,    // 叫地主
  qiangdizhu = 3,   // 抢地主
  play = 4          // 出牌
}

export interface IGamePlayer {
  uid: number,            // uid
  sid: string,            // sid
  seat: number,           // 座位
  role: IRole,            // 身份
  score: QiangdizhuState, // 抢地主的分数
  record: IRecord,        // 战绩
  cards: Array<ICard>     // 手牌
}

export enum IRole {
  Unknow = 0,     // 未分配
  Peasant = 1,    // 农名
  Landlord = 2    // 地主
}

export enum QiangdizhuState {
  none = -1,  //
  zero = 0,   // 不抢
  one = 1,    // 一分
  two = 2,    // 两分
  three = 3   // 三分
}

export interface IRecord {
  win: number,      // 赢
  lose: number,     // 输
  escape: number,   // 逃跑
  gold: number,     // 金币
}
